using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;
using System.Web.Security;

namespace TemplateWeb.DTO
{
    public struct BaseInfo
    {
        public string UserName;
        public string Email;
        public string Role;
        public DateTime CreateDate;
        public BaseInfo(string userName, string email, string role, DateTime createDate)
        {
            this.UserName = userName;
            this.Email = email;
            this.Role = role;
            this.CreateDate = createDate;
        }
    };
	/// <summary>
	/// Data transfer object which is associated with NguoiDung table in database
	/// </summary>
	public class NguoiDungDTO
	{
        
		public Guid ID { get; set; }
		public string HoTen { get; set; }
		public string DiaChi { get; set; }
		public string SoDienThoai { get; set; }
		public string SoTaiKhoan { get; set; }
        public BaseInfo aspnet_Users { get; set; }

		public static NguoiDungDTO Translate(DataRow row)
		{
            var dto = new NguoiDungDTO
            {
                ID = Guid.Parse(row["ID"].ToString()),
                HoTen = row["HoTen"].ToString(),
                DiaChi = row["DiaChi"].ToString(),
                SoDienThoai = row["SoDienThoai"].ToString(),
                SoTaiKhoan = row["SoTaiKhoan"].ToString(),
            };

            var mUser = Membership.GetUser(dto.ID);
            dto.aspnet_Users = new BaseInfo(mUser.UserName, mUser.Email, Roles.GetRolesForUser(mUser.UserName)[0], mUser.CreationDate);
			return dto;
		}
	}
}